#!/usr/bin/env python
# -*- encoding: utf-8 -*-
"""
@File    :   get_net.py
@Time    :   20230829161715
@Author  :   
@Version :   1.0
@Contact :   
@License :   
@Desc    :   None
"""

import requests

class GetNet():
    def __init__(self, headers):
        self.headers = headers
        self.proxy_socks5 = "127.0.0.1:10808"
        self.proxy_http = "127.0.0.1:10809"
        self.proxies_socks5 = {"http": "socks5://" + self.proxy_socks5,"https": "socks5://" + self.proxy_socks5}
        self.proxies_http = {"http": "http://" + self.proxy_http, "https":"http://" + self.proxy_http}
        self.timeout = 10
    
    def get(self, url) -> requests.models.Response:
        try:
            response = requests.get(url,headers=self.headers,proxies=self.proxies_http, timeout=self.timeout)
            print(response.status_code)
        except requests.exceptions.ConnectionError as Ce:
            return "Connection Error"
        except requests.exceptions.ReadTimeout as RTe:
            return "Read Timeout"
        else:
            return response
    
    def post(self, url, post_data) -> requests.models.Response:
        try:
            response = requests.post(url,headers = self.headers, data = post_data, proxies = self.proxies_http, timeout = self.timeout)
            print(response.status_code)
        except requests.exceptions.ConnectionError as Ce:
            return "Connection Error"
        except requests.exceptions.ReadTimeout as RTe:
            return "Read Timeout"
        else:
            return response